package com.cl.security.base.controller;

import cn.hutool.json.JSONUtil;
import com.cl.security.base.service.BaseService;
import com.cl.security.common.result.CommonResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

public class BaseController<Entity,Service extends BaseService> {
    private final Service service;
    private final Class<?> clazz;

    public BaseController(Service service, Class<?> clazz) {
        this.service = service;
        this.clazz = clazz;
    }
    @GetMapping("page")
    public CommonResult page(int pageNumber, int pageSize, String contain,Entity entity) {
        return service.page(pageNumber, pageSize, entity) ;
    }
    @GetMapping("list")
    public CommonResult list() {
        return service.list();
    }
    @PostMapping("saveAll")
    public CommonResult saveAll(String data) {
        return service.saveAll(JSONUtil.toList(JSONUtil.parseArray(data),clazz));
    }
}
